﻿/**
 ** @作者:	   王桂龙 QQ731513122
 ** @日期:	   2019.12.6
 ** @简介:     增加了几个状态，增加了长按事件     
 */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace BHXJDOTNET.OLD
{
    public class BHXJButton:Button,IBHXJZOOM
    {
        #region 继承于ZOOM接口的属性和方法
        private Point _OriginPoint = new Point(0, 0);
        [Description("原点(慎用,在足够了解BHXJZoom的情况下使用)"), Category("BHXJZoom")]
        /// <summary>
        /// 原点
        /// </summary>
        public Point OriginPoint
        {
            get
            { return this._OriginPoint; }
            set
            {
                if (this._OriginPoint != value)
                {
                    this._OriginPoint = value;
                    if (DesignMode)
                        this.IniLocation = this.BHXJGetIniLocationInDesignMode();
                }
            }
        }
        private bool _AutoOrigin = false;
        [Description("自动更改原点模式(只在设计模式下有用)"), Category("BHXJZoom")]
        /// <summary>
        /// 自动更改原点模式(只在设计模式下有用)
        /// </summary>
        public bool AutoOrigin
        {
            get
            {
                return this._AutoOrigin;
            }
            set
            {
                if (this._AutoOrigin != value)
                {
                    this._AutoOrigin = value;
                    if (DesignMode)
                    {
                        if (this.AutoOrigin)
                        {
                            this.OriginPoint = this.Location;
                        }
                        else
                        {
                            this.OriginPoint = new Point(0, 0);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// 初始尺寸
        /// </summary>
        [Browsable(false)]
        public Size IniSize { get; set; }
        /// <summary>
        /// 初始位置
        /// </summary>
        [Browsable(false)]
        public Point IniLocation { get; set; }
        /// <summary>
        /// 初始字体
        /// </summary>
        [Browsable(false)]
        public Font IniFont { get; set; }

        #endregion
        /// <summary>
        /// _按钮类型
        /// </summary>
        private BHXJButtonType _ButtonType = BHXJButtonType.常规;
        [Description("按钮类型"), Category("BHXJ")]
        /// <summary>
        /// 按钮类型
        /// </summary>
        public BHXJButtonType ButtonType
        {
            get
            {
                return this._ButtonType;
            }
            set
            {
                if (this._ButtonType != value)
                {
                    this._ButtonType = value;
                    this.Invalidate();
                }
            }
        }


        /// <summary>
        /// 鼠标按下标记
        /// </summary>
        private MouseDownStamp mouseDownStamp = new MouseDownStamp();
        /// <summary>
        /// 处理鼠标长按事件的定时器
        /// </summary>
        private System.Windows.Forms.Timer mouseDownTimer = new System.Windows.Forms.Timer();
        /// <summary>
        /// 鼠标按下事件
        /// </summary>
        [Description("自定义鼠标按下事件，长按多次触发，BHXJMouseClick为True时触发"), Category("BHXJ")]
        public event BHXJMouseClick BHXJMouseClickEvent;
        /// <summary>
        /// _触发BHXJMouseClickEvent事件
        /// </summary>
        private bool _BHXJMouseClick=false;
        [Description("触发BHXJMouseClickEvent事件"), Category("BHXJ")]
        /// <summary>
        /// 触发BHXJMouseClickEvent事件
        /// </summary>
        public  bool BHXJMouseClick
        {
            get { return this._BHXJMouseClick; }
            set 
            {
                if (this._BHXJMouseClick != value)
                {
                    this._BHXJMouseClick = value;
                    this.mouseDownTimer.Enabled = this._BHXJMouseClick;
                }
            }
        }

        /// <summary>
        /// _不能使用状态文字颜色
        /// </summary>
        private Color _UnEnabelForeColor = Color.FromArgb(32,32,32);
        [Description("不能使用状态文字颜色"), Category("BHXJ")]
        /// <summary>
        /// 不能使用状态文字颜色
        /// </summary>
        public Color UnEnableForeColor
        {
            get { return this._UnEnabelForeColor; }
            set
            {
                if (this._UnEnabelForeColor != value)
                {
                    this._UnEnabelForeColor = value;
                    this.Invalidate();
                }
            }
        }

        /// <summary>
        /// 鼠标进入
        /// </summary>
        private bool beMouseEnter = false;
        /// <summary>
        /// 鼠标按下
        /// </summary>
        private bool beMouseDown = false;


        /// <summary>
        /// _鼠标进入颜色
        /// </summary>
        private Color _MouseEnterColor = Color.FromArgb(32,32,32);
        [Description("鼠标进入颜色"), Category("BHXJ")]
        /// <summary>
        /// 鼠标进入颜色
        /// </summary>
        public Color MouseEnterColor 
        {
            get { return _MouseEnterColor; }
            set 
            {
                if (this._MouseEnterColor != value)
                {
                    this._MouseEnterColor = value;
                    this.Invalidate();
                }
            }
        }

        /// <summary>
        /// 鼠标按下颜色
        /// </summary>
        private Color _MouseDownColor = Color.FromArgb(64,64,64);
        [Description("鼠标按下颜色"), Category("BHXJ")]
        public Color MouseDownColor
        {
            get { return this._MouseDownColor; }
            set 
            {
                if (this._MouseDownColor != value)
                {
                    this._MouseDownColor = value;
                    this.Invalidate();
                }
            }
        }

        public BHXJButton()
        {

            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);

            //this.ForeColor = Color.FromArgb(16, 208, 208);
            //this.BackColor = Color.FromArgb(32, 32, 32);

            this.ForeColor = Color.Silver;
            this.BackColor = Color.FromArgb(64, 64, 64);
            this.FlatStyle = FlatStyle.Flat;
            this.FlatAppearance.BorderSize = 0;

            #region 设计时,变化事件
            if (System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime)
            {
                //设计时事件
                this.SizeChanged += new EventHandler(this.BHXJ_SizeChangedInDesignMode);
                this.FontChanged += new EventHandler(this.BHXJ_FontChangedInDesignMode);
                this.LocationChanged += new EventHandler(this.BHXJ_LocationChangedInDesignMode);
            }
            #endregion
            //防止字体在设计器中添加该控件时候自动追随父控件
            this.Font = this.Font;

            #region 设置初始值BHXJ
            //设置初始
            this.IniSize = this.Size;
            this.IniFont = this.Font;
            this.IniLocation = this.BHXJGetIniLocationInDesignMode();
            #endregion


            //鼠标事件
            this.MouseDown += new MouseEventHandler(BHXJButton_MouseDown);
            this.MouseUp += new MouseEventHandler(BHXJButton_MouseUp);
            //timer
            this.mouseDownTimer.Interval = 60;
            this.mouseDownTimer.Tick+=new EventHandler(mouseDownTimer_Tick);
            this.mouseDownTimer.Enabled = this._BHXJMouseClick;

            this.MouseEnter+=new EventHandler(BHXJButton_MouseEnter);
            this.MouseLeave+=new EventHandler(BHXJButton_MouseLeave);
        }

        /// <summary>
        /// 绘制函数
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics gs = e.Graphics;
            //gs.SmoothingMode = SmoothingMode.AntiAlias;
            SolidBrush brush = new SolidBrush(this.BackColor);
            SolidBrush enterbrush = new SolidBrush(this._MouseEnterColor);
            SolidBrush downbrush = new SolidBrush(this._MouseDownColor);
            if (this.beMouseDown)
            {
                gs.FillRectangle(downbrush, 0, 0, this.Width, this.Height); 
            }
            else if (this.beMouseEnter)
            {
                gs.FillRectangle(enterbrush, 0, 0, this.Width, this.Height);
            }
            else
            {
                gs.FillRectangle(brush, 0, 0, this.Width, this.Height);
            }

            Pen pen = new Pen(this.ForeColor);
            if (this.beMouseDown)
            {
                gs.DrawLine(pen, 0, 0, this.Width - 1, 0);
                gs.DrawLine(pen, 0, 0, 0, this.Height - 1);
                gs.DrawLine(pen, 0, this.Height - 1, this.Width - 1, this.Height - 1);
                gs.DrawLine(pen, this.Width - 1, 0, this.Width - 1, this.Height - 1);
            }

            switch (this.ButtonType)
            {
                case BHXJButtonType.放大:
                    this.PaintMaximize(gs);
                    break;
                case BHXJButtonType.还原:
                    this.PaintReduction(gs);
                    break;
                case BHXJButtonType.最小化:
                    this.PaintMinimize(gs);
                    break;
                case BHXJButtonType.关闭:
                    this.PaintClose(gs);
                    break;
                case BHXJButtonType.左:
                    this.PaintLeft(gs);
                    break;
                case BHXJButtonType.右:
                    this.PaintRight(gs);
                    break;
                case BHXJButtonType.上:
                    this.PaintUp(gs);
                    break;
                case BHXJButtonType.下:
                    this.PaintDown(gs);
                    break;
                case BHXJButtonType.删除:
                    this.PaintDelete(gs);
                    break;
                default:
                    break;
            }
            gs.SmoothingMode = SmoothingMode.None;

            


            //文字

            Brush textBrush = new SolidBrush(this.ForeColor);

            if (!this.Enabled)
            {
                textBrush = new SolidBrush(this._UnEnabelForeColor);
            }

            PointF pf = new PointF();
            SizeF textarea = e.Graphics.MeasureString(this.Text, this.Font);

            Label testlabel = new Label();
            testlabel.Text = this.Text;
            testlabel.AutoSize = true;
            testlabel.Visible = false;
            this.Controls.Add(testlabel);

            float centerY = (this.Height - testlabel.Size.Height) / 2;
            float farY = this.Height - testlabel.Size.Height;

            float centerX = (this.Width - textarea.Width) / 2;
            float farX = this.Width - textarea.Width;
            this.Controls.Remove(testlabel);
            testlabel.Dispose();

            switch (this.TextAlign)
            {
                case ContentAlignment.TopLeft:
                    pf.Y = 0;
                    pf.X = 0;             
                    break;
                case ContentAlignment.TopCenter:
                    pf.Y = 0;
                    pf.X = centerX; 
                    break;
                case ContentAlignment.TopRight:
                    pf.Y = 0;
                    pf.X = farX; 
                    break;
                case ContentAlignment.MiddleLeft:
                    pf.Y = centerY;
                    pf.X = 0; 
                    break;
                case ContentAlignment.MiddleCenter:
                    pf.Y = centerY;
                    pf.X = centerX; 
                    break;
                case ContentAlignment.MiddleRight:
                    pf.Y = centerY;
                    pf.X = farX; 
                    break;
                case ContentAlignment.BottomLeft:
                    pf.Y = farY;
                    pf.X = 0; 
                    break;
                case ContentAlignment.BottomCenter:
                    pf.Y = farY;
                    pf.X = centerX; 
                    break;
                case ContentAlignment.BottomRight:
                    pf.Y = farY;
                    pf.X = farX; 
                    break;
            }
            StringFormat s = new StringFormat();
            s.Alignment = StringAlignment.Near;
            s.LineAlignment = StringAlignment.Near;
            e.Graphics.DrawString(this.Text, this.Font, textBrush, pf, s);

        }


        /// <summary>
        /// 绘制最大化图标
        /// </summary>
        /// <param name="gs"></param>
        private void PaintMaximize(Graphics gs)
        {
            Rectangle buttonArea = this.DisplayRectangle;

            int bw = buttonArea.Width;
            int bh = buttonArea.Height;

            //线宽
            int w = (int)((bw > bh) ? (bh * 0.05f) : (bw * 0.05f));
            if (w == 0)
                w = 1;
            SolidBrush brush = new SolidBrush(this.ForeColor);
            {
                int x = (int)(bw * 0.25);
                int y = (int)(bh * 0.25);
                //左右x坐标
                int lx = x;
                int rx = bw - x - w;
                //上下y坐标
                int ty = y;
                int by = bh - y - w;

                //宽和高
                int ww = bw - 2 * x;
                int hh = bh - 2 * y;

                //左
                gs.FillRectangle(brush, lx, ty, w, hh);
                //右
                gs.FillRectangle(brush, rx, ty, w, hh);
                //上
                gs.FillRectangle(brush, lx, ty, ww, 3 * w);
                //下
                gs.FillRectangle(brush, lx, by, ww, w);
            }
            brush.Dispose();
        }
        /// <summary>
        /// 绘制最小化图标
        /// </summary>
        /// <param name="gs"></param>
        private void PaintMinimize(Graphics gs)
        {
            Rectangle buttonArea = this.DisplayRectangle;

            float bw = buttonArea.Width;
            float bh = buttonArea.Height;

            
            int w = (int)((bw > bh) ? (bh * 0.05f) : (bw * 0.05f));
            if (w == 0)
                w = 1;
            Pen bpen = new Pen(this.ForeColor, 3 * w);
            SolidBrush bgbrush = new SolidBrush(this.BackColor);
            //背景
            //gs.FillRectangle(bgbrush, 1, 1, bw - 2, bh - 2);


            gs.DrawLine(bpen, (int)(bw / 4), (int)(bh * 0.65 - 1.5 * w), (int)(3 * bw / 4), (int)(bh * 0.65- 1.5 * w));

            bpen.Dispose();
            bgbrush.Dispose();
        }
        /// <summary>
        /// 绘制还原图标
        /// </summary>
        /// <param name="gs"></param>
        private void PaintReduction(Graphics gs)
        {
            Rectangle buttonArea = this.DisplayRectangle;

            int bw = buttonArea.Width;
            int bh = buttonArea.Height;

            int w = (int)((bw > bh) ? (bh * 0.0375) : (bw * 0.0375));
            if (w == 0)
                w = 1;

            SolidBrush brush = new SolidBrush(this.ForeColor);
            {
                //左右x坐标
                int lx = (int)(bw * 0.375);
                int rx = (int)(bw - bw * 0.25 - w);
                //上下y坐标
                int ty = (int)(bh * 0.25);
                int by = (int)(bh - bh * 0.375 - w);

                //宽和高
                int ww = rx - lx + w;
                int hh = by - ty + w;

                //左
                gs.FillRectangle(brush, lx, ty, w, (int)(bh * 0.375) - ty);
                //右
                gs.FillRectangle(brush, rx, ty, w, hh);
                //上
                gs.FillRectangle(brush, lx, ty, ww, 3 * w);
                //下
                gs.FillRectangle(brush, (int)(bw * 0.625), by, rx - (int)(bw * 0.625) + w, w);
            }
            {
                //左右x坐标
                int lx = (int)(bw * 0.25);
                int rx = (int)(bw - bw * 0.375 - w);
                //上下y坐标
                int ty = (int)(bh * 0.375);
                int by = (int)(bh - bh * 0.25 - w);

                //宽和高
                int ww = rx - lx + w;
                int hh = by - ty + w;

                //左
                gs.FillRectangle(brush, lx, ty, w, hh);
                //右
                gs.FillRectangle(brush, rx, ty, w, hh);
                //上
                gs.FillRectangle(brush, lx, ty, ww, 3 * w);
                //下
                gs.FillRectangle(brush, lx, by, ww, w);
            }
        }
        /// <summary>
        /// 绘制关闭图标
        /// </summary>
        /// <param name="gs"></param>
        private void PaintClose(Graphics gs)
        {
            Rectangle buttonArea = this.DisplayRectangle;

            int bw = buttonArea.Width;
            int bh = buttonArea.Height;

            int w = (int)((bw > bh) ? (bh * 0.05f) : (bw * 0.05f));
            if (w == 0)
                w = 1;
            Pen bpen = new Pen(this.ForeColor, 2 * w);
            gs.SmoothingMode = SmoothingMode.AntiAlias;
            int x = (int)(bw * 0.25);
            int y = (int)(bh * 0.25);

            gs.SetClip(new RectangleF(x,y,bw-2*x,bh-2*y));
            gs.DrawLine(bpen, 0, 0, bw-1, bh-1);
            gs.DrawLine(bpen, 0, bh-1, bw-1, 0);
            gs.SmoothingMode = SmoothingMode.Default;
            gs.ResetClip();

            bpen.Dispose();

        }

        /// <summary>
        /// 绘制左方向图标
        /// </summary>
        /// <param name="gs"></param>
        private void PaintLeft(Graphics gs)
        {
            //gs.SmoothingMode = SmoothingMode.AntiAlias;
            //Rectangle buttonArea = this.DisplayRectangle;

            //double bw = buttonArea.Width;
            //double bh = buttonArea.Height;

            //double wx = (2 * bw > bh) ? (bh * 0.5) : (bw * 1);

            //SolidBrush Brush = new SolidBrush(this.ForeColor);

            //double startx = ((bw - wx) * 0.5);
            //double starty = ((bh - 2 * wx) * 0.5);

            //Point point1 = new Point((int)startx, (int)(bh / 2 - 0.5));
            //Point point2 = new Point((int)(startx + wx - 1), (int)starty);
            //Point point3 = new Point((int)(startx + wx - 1), (int)(starty + 2 * wx - 1));
            //Point[] curvePoints = { point1, point2, point3 };
            //gs.FillPolygon(Brush, curvePoints);

            //Brush.Dispose();
            gs.SmoothingMode = SmoothingMode.AntiAlias;
            Rectangle buttonArea = this.DisplayRectangle;

            double bw = buttonArea.Width;
            double bh = buttonArea.Height;

            SolidBrush Brush = new SolidBrush(this.ForeColor);

            Point point1 = new Point(0, (int)(bh / 2 - 0.5));
            Point point2 = new Point((int)(bw / 2 - 0.5), (int)(bh - 1));
            Point point3 = new Point((int)(bw / 2 - 0.5), (int)(bh * 0.75 - 0.5));
            Point point4 = new Point((int)(bw-1), (int)(bh * 0.75 - 0.5));
            Point point5 = new Point((int)(bw - 1), (int)(bh * 0.25 - 0.5));
            Point point6 = new Point((int)(bw / 2 - 0.5), (int)(bh * 0.25 - 0.5));
            Point point7 = new Point((int)(bw / 2 - 0.5), 0);
            Point[] curvePoints = { point1, point2, point3, point4, point5, point6, point7};
            gs.FillPolygon(Brush, curvePoints);

            Brush.Dispose();
        }

        /// <summary>
        /// 绘制右方向图标
        /// </summary>
        /// <param name="gs"></param>
        private void PaintRight(Graphics gs)
        {
            //gs.SmoothingMode = SmoothingMode.AntiAlias;
            //Rectangle buttonArea = this.DisplayRectangle;

            //double bw = buttonArea.Width;
            //double bh = buttonArea.Height;

            //double wx = (2 * bw > bh) ? (bh * 0.5) : (bw * 1);

            //SolidBrush Brush = new SolidBrush(this.ForeColor);

            //double startx = ((bw - wx) * 0.5);
            //double starty = ((bh - 2 * wx) * 0.5);

            //Point point1 = new Point((int)(startx + wx - 1), (int)(bh / 2 - 0.5));
            //Point point2 = new Point((int)(startx), (int)starty);
            //Point point3 = new Point((int)(startx), (int)(starty + 2 * wx - 1));
            //Point[] curvePoints = { point1, point2, point3 };
            //gs.FillPolygon(Brush, curvePoints);

            //Brush.Dispose();
            gs.SmoothingMode = SmoothingMode.AntiAlias;
            Rectangle buttonArea = this.DisplayRectangle;

            double bw = buttonArea.Width;
            double bh = buttonArea.Height;

            SolidBrush Brush = new SolidBrush(this.ForeColor);

            Point point1 = new Point((int)(bw - 1), (int)(bh / 2 - 0.5));
            Point point2 = new Point((int)(bw / 2 - 0.5), (int)(bh - 1));
            Point point3 = new Point((int)(bw / 2 - 0.5), (int)(bh * 0.75 - 0.5));
            Point point4 = new Point(0, (int)(bh * 0.75 - 0.5));
            Point point5 = new Point(0, (int)(bh * 0.25 - 0.5));
            Point point6 = new Point((int)(bw / 2 - 0.5), (int)(bh * 0.25 - 0.5));
            Point point7 = new Point((int)(bw / 2 - 0.5), 0);
            Point[] curvePoints = { point1, point2, point3, point4, point5, point6, point7 };
            gs.FillPolygon(Brush, curvePoints);

            Brush.Dispose();
        }
        /// <summary>
        /// 绘制上方向图标
        /// </summary>
        /// <param name="gs"></param>
        private void PaintUp(Graphics gs)
        {
            //gs.SmoothingMode = SmoothingMode.AntiAlias;
            //Rectangle buttonArea = this.DisplayRectangle;

            //double bw = buttonArea.Width;
            //double bh = buttonArea.Height;

            //double wx = (bw > 2 * bh) ? (bh * 2) : (bw * 1);

            //SolidBrush Brush = new SolidBrush(this.ForeColor);

            //double startx = ((bw - wx) * 0.5);
            //double starty = ((bh - 0.5 * wx) * 0.5);

            //Point point1 = new Point((int)(bw / 2 - 0.5), (int)starty);
            //Point point2 = new Point((int)(startx), (int)(starty + 0.5 * wx - 1));
            //Point point3 = new Point((int)(startx + wx - 1), (int)(starty + 0.5 * wx - 1));
            //Point[] curvePoints = { point1, point2, point3 };
            //gs.FillPolygon(Brush, curvePoints);

            //Brush.Dispose();
            gs.SmoothingMode = SmoothingMode.AntiAlias;
            Rectangle buttonArea = this.DisplayRectangle;

            double bw = buttonArea.Width;
            double bh = buttonArea.Height;

            SolidBrush Brush = new SolidBrush(this.ForeColor);

            Point point1 = new Point((int)(bw / 2 - 0.5), 0);
            Point point2 = new Point(0, (int)(bh / 2 - 0.5));
            Point point3 = new Point((int)(bw * 0.25 - 0.5), (int)(bh / 2 - 0.5));
            Point point4 = new Point((int)(bw * 0.25 - 0.5), (int)(bh - 1));
            Point point5 = new Point((int)(bw * 0.75 - 0.5), (int)(bh - 1));
            Point point6 = new Point((int)(bw * 0.75 - 0.5), (int)(bh / 2 - 0.5));
            Point point7 = new Point((int)(bw - 1), (int)(bh / 2 - 0.5));
            Point[] curvePoints = { point1, point2, point3, point4, point5, point6, point7 };
            gs.FillPolygon(Brush, curvePoints);

            Brush.Dispose();
        }
        /// <summary>
        /// 绘制下方向图标
        /// </summary>
        /// <param name="gs"></param>
        private void PaintDown(Graphics gs)
        {
            //gs.SmoothingMode = SmoothingMode.AntiAlias;
            //Rectangle buttonArea = this.DisplayRectangle;

            //double bw = buttonArea.Width;
            //double bh = buttonArea.Height;

            //double wx = (bw > 2 * bh) ? (bh * 2) : (bw * 1);

            //SolidBrush Brush = new SolidBrush(this.ForeColor);

            //double startx = ((bw - wx) * 0.5);
            //double starty = ((bh - 0.5 * wx) * 0.5);

            //Point point1 = new Point((int)(bw / 2 - 0.5), (int)(starty+0.5*wx-1));
            //Point point2 = new Point((int)(startx), (int)(starty ));
            //Point point3 = new Point((int)(startx + wx - 1), (int)(starty));
            //Point[] curvePoints = { point1, point2, point3 };
            //gs.FillPolygon(Brush, curvePoints);

            //Brush.Dispose();
            gs.SmoothingMode = SmoothingMode.AntiAlias;
            Rectangle buttonArea = this.DisplayRectangle;

            double bw = buttonArea.Width;
            double bh = buttonArea.Height;

            SolidBrush Brush = new SolidBrush(this.ForeColor);

            Point point1 = new Point((int)(bw / 2 - 0.5), (int)(bh - 1));
            Point point2 = new Point(0, (int)(bh / 2 - 0.5));
            Point point3 = new Point((int)(bw * 0.25 - 0.5), (int)(bh / 2 - 0.5));
            Point point4 = new Point((int)(bw * 0.25 - 0.5), 0);
            Point point5 = new Point((int)(bw * 0.75 - 0.5), 0);
            Point point6 = new Point((int)(bw * 0.75 - 0.5), (int)(bh / 2 - 0.5));
            Point point7 = new Point((int)(bw - 1), (int)(bh / 2 - 0.5));
            Point[] curvePoints = { point1, point2, point3, point4, point5, point6, point7 };
            gs.FillPolygon(Brush, curvePoints);

            Brush.Dispose();
        }

        /// <summary>
        /// 绘制删除图标
        /// </summary>
        /// <param name="gs"></param>
        private void PaintDelete(Graphics gs)
        {
            Rectangle buttonArea = this.DisplayRectangle;

            int bw = buttonArea.Width;
            int bh = buttonArea.Height;

            int w = (int)((bw > bh) ? (bh * 0.05f) : (bw * 0.05f));
            if (w == 0)
                w = 1;
            Pen bpen = new Pen(this.ForeColor, 6 * w);
            gs.SmoothingMode = SmoothingMode.AntiAlias;
            int x = (int)(bw * 0.15);
            int y = (int)(bh * 0.15);

            int lx = x;
            int rx = bw - x - 1;

            int ty = y;
            int by = bh - y - 1;

            gs.DrawLine(bpen, lx, ty, rx, by);
            gs.DrawLine(bpen, lx, by, rx, ty);
            gs.SmoothingMode = SmoothingMode.Default;


            bpen.Dispose();

        }
        /// <summary>
        /// 鼠标按下事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="arg"></param>
        private void BHXJButton_MouseDown(Object sender,EventArgs e)
        {
            this.beMouseDown = true;
            if (this._BHXJMouseClick)
            {
                //先触发一次
                if (this.BHXJMouseClickEvent != null)
                {
                    this.BHXJMouseClickEvent(this);
                }
                this.mouseDownStamp.DT = DateTime.Now;
                //鼠标按下
                this.mouseDownStamp.MouseDown = true;
            }   
        }
        /// <summary>
        /// 鼠标抬起事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="arg"></param>
        private void BHXJButton_MouseUp(Object sender, EventArgs e)
        {
            this.beMouseDown = false;
            //鼠标抬起
            this.mouseDownStamp.MouseDown = false;
            this.Invalidate();
        }
        /// <summary>
        /// 处理长按timer触发事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mouseDownTimer_Tick(Object sender, EventArgs e)
        {
            if (this.mouseDownStamp.MouseDown)
            {
                if ((DateTime.Now - this.mouseDownStamp.DT).TotalMilliseconds > 500)
                {
                    if (this.BHXJMouseClickEvent != null)
                    {
                        this.BHXJMouseClickEvent(this);
                    }
                }
            }
        }

        /// <summary>
        /// 鼠标进入控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BHXJButton_MouseEnter(Object sender, EventArgs e)
        {
            this.beMouseEnter = true;
        }

        /// <summary>
        /// 鼠标离开控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BHXJButton_MouseLeave(Object sender, EventArgs e)
        {
            this.beMouseEnter = false ;
        }

        /// <summary>
        /// 按钮状态
        /// </summary>
        public enum BHXJButtonType
        {
            常规 = 1,
            放大 = 2,
            还原 = 3,
            最小化 = 4,
            关闭 = 5,
            上 = 6,
            下 = 7,
            左 = 8,
            右 = 9,
            删除=10
        }
    }
}
